package com.xhs.controller;

import com.xhs.dto.request.CopyFileRequest;
import com.xhs.dto.request.DownloadFileRequest;
import com.xhs.message.ReturnResult;
import com.xhs.service.CopyFileService;
import com.xhs.service.DownloadFileService;
import com.xhs.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @desc: 关于操作文件的接口
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/3 22:08
 * @version: JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/file")
public class DownloadFileController {
    @Resource
    private DownloadFileService downloadFileService;
    @Resource
    private ExcelService excelService;

    @Resource
    private CopyFileService copyFileService;

    /**
     * 拷贝文件
     *
     * @param copyFileRequest
     * @return ReturnResult<Object>
     */
    @PostMapping("/copyFile")
    public ReturnResult<Object> copyFile(@RequestBody CopyFileRequest copyFileRequest) {
        return copyFileService.copyFile(copyFileRequest);
    }

    /**
     * 根据url从服务器下载文件到指定位置
     *
     * @param downloadFileRequest
     * @return ReturnResult<Object>
     */
    @PostMapping("/downloadFile")
    public ReturnResult<Object> downloadFile(@RequestBody DownloadFileRequest downloadFileRequest) {
        return downloadFileService.downloadFile(downloadFileRequest);
    }

    /**
     * 导出Excel
     *
     * @param response
     * @return ReturnResult<Object>
     */
    @GetMapping("/listExcel")
    public void listExcel(HttpServletResponse response) {
        excelService.listExcel(response);
    }

    /**
     * 导出Excel
     *
     * @param response
     * @return ReturnResult<Object>
     */
    @GetMapping("/mapExcel")
    public void mapExcel(HttpServletResponse response) {
        excelService.mapExcel(response);
    }
}
